class BASFScript(object):
    basf_header = '''module register fix_mdst
module register {module_name} 
path add_module main fix_mdst {module_name}
'''
    basf_process_event = "process_event {input_file} {nevents}\n"

    basf_footer = 'terminate\n'
    def __init__(self, module_name, input_files, parameters, 
                 hist_file=None, nevents=0):
        self.scriptbuf = []
        self.scriptbuf.append(
            BASFScript.basf_header.format(module_name=module_name))
        
        for key, value in parameters.iteritems():
            line = "module put_parameter {0} {1}\{2}"
            self.scriptbuf.append(line.format(module_name,
                                              key, value))
        self.scriptbuf.append("initialize")
        if hist_file:
            self.scriptbuf.append("histogram define " + hist_file)

        if type(input_files) == type('hi'):
            self.scriptbuf.append(
                BASFScript.basf_process_event.format(input_file=input_files, 
                                                     nevents=nevents))
        else:
            for f in input_files:
                self.scriptbuf.append(
                    BASFScript.basf_process_event.format(input_file=f, 
                                                         nevents=nevents))

        self.scriptbuf.append(BASFScript.basf_footer)
        self.scriptbuf.append('\n')

    def __str__(self):
        return '\n'.join(self.scriptbuf)

            
